package com.woniuxy.woniuticket.moviemodule.controller;

import com.woniuxy.woniuticket.moviemodule.service.CinemaSeatsService;
import com.woniuxy.woniuticket.pojo.CinemaSeats;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Utopia
 * @title: CinemaSeatsController
 * @projectName woniuticket
 * @description: TODO
 * @date 2019/6/10 19:54
 */

@Controller
@RequestMapping("/seats")
public class CinemaSeatsController {

    @Resource
    private CinemaSeatsService cinemaSeatsService;

    @RequestMapping("selectBySid")
    @ResponseBody
    public Object selectSeatsBySid(CinemaSeats cinemaSeats){
        return cinemaSeatsService.selectSeatsBySid(cinemaSeats);
    }

    @RequestMapping("/add")
    @ResponseBody
    public Object addSeat(String arr){
        String[] ids = arr.split(",");
        List<String> list = new ArrayList<>();
        for (String seat:ids) {
            int num = Integer.parseInt(seat);
            int seatRow = (int) (Math.floor(num/17)+1);
            int seatColumn = (int) (num - Math.floor(num/17)*17);
            System.out.println(seatColumn+":"+seatRow);
            list.add(String.valueOf(seatRow)+","+String.valueOf(seatColumn));
        }
        return null;
    }
}
